package com.dayu.web.controller.recovery;

import java.util.List;

import com.dayu.common.annotation.RepeatSubmit;
import com.dayu.recovery.service.IRecoveryGoodsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.recovery.domain.RecoveryCollect;
import com.dayu.recovery.service.IRecoveryCollectService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 回收管理Controller
 *
 * @author HK
 * @date 2021-04-16
 */
@RestController
@RequestMapping("/recovery/collect")
public class RecoveryCollectController extends BaseController
{
    @Autowired
    private IRecoveryCollectService recoveryCollectService;

    /**
     * 查询回收管理列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:collect:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecoveryCollect recoveryCollect)
    {
        startPage();
        List<RecoveryCollect> list = recoveryCollectService.selectRecoveryCollectList(recoveryCollect);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('recovery:collect:list')")
    @GetMapping("/list/number")
    public AjaxResult listNumber(RecoveryCollect recoveryCollect) {
        return AjaxResult.success(recoveryCollectService.selectCollectNumber(recoveryCollect));
    }

    /**
     * 导出回收管理列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:collect:export')")
    @Log(title = "回收管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RecoveryCollect recoveryCollect)
    {
        List<RecoveryCollect> list = recoveryCollectService.selectRecoveryCollectList(recoveryCollect);
        ExcelUtil<RecoveryCollect> util = new ExcelUtil<RecoveryCollect>(RecoveryCollect.class);
        return util.exportExcel(list, "collect");
    }

    /**
     * 获取回收管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:collect:query')")
    @GetMapping(value = "/{collectId}")
    public AjaxResult getInfo(@PathVariable("collectId") Long collectId)
    {
        return AjaxResult.success(recoveryCollectService.selectRecoveryCollectById(collectId));
    }

    /**
     * 新增回收管理
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('recovery:collect:add')")
    @Log(title = "回收管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecoveryCollect recoveryCollect)
    {
        return toAjax(recoveryCollectService.insertRecoveryCollect(recoveryCollect));
    }

    /**
     * 修改回收管理
     */
    @PreAuthorize("@ss.hasPermi('recovery:collect:edit')")
    @Log(title = "回收管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecoveryCollect recoveryCollect)
    {
        return toAjax(recoveryCollectService.updateRecoveryCollect(recoveryCollect));
    }

    /**
     * 删除回收管理
     */
    @PreAuthorize("@ss.hasPermi('recovery:collect:remove')")
    @Log(title = "回收管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectIds}")
    public AjaxResult remove(@PathVariable Long[] collectIds)
    {
        return toAjax(recoveryCollectService.deleteRecoveryCollectByIds(collectIds));
    }

    /**
     * 批量生成
     * @param recoveryCollect
     * @return
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('recovery:collect:create')")
    @PostMapping("/create/goods")
    public AjaxResult createGoodsList(@RequestBody RecoveryCollect recoveryCollect) {
        return toAjax(recoveryCollectService.generateRecoveryGoods(recoveryCollect));
    }
}
